import {promptBox,toast} from 'nc-lightapp-front';
import { getAppPageConfig } from '../../../../hrpub/common/utils/utils';

export default class MainAction{
    constructor(comp){
        this.comp = comp;
        if(comp.props.use){
            comp.props.use.form('handcondform');
            comp.props.use.editTable('handcondgrid', 'dishandcondgrid');
            comp.props.use.editTable('handitemsetgrid');
        }
    }

    // appConfig ={
    //     pagecode :'60091050nccloud',
    //     appcode : '60091050'
    // }

    //获取模版数据
    getTemplate =()=>{
        const {props,action} = this.comp
        props.createUIDom(this.appConfig,(data)=>{
            this.getMulitiLange()
            //手动添加一个离职模版  和入职模版一致
            let items = data.template.handcondgrid.items
            let dishandcondgrid ={
                code: 'dishandcondgrid',
                moduletype: 'table',
                items: items
            }
            props.meta.setMeta(data.template)
            props.meta.addMeta({'dishandcondgrid':dishandcondgrid})
            props.button.setButtons(data.button)
        })

    }

    //获取多语
    getMulitiLange =(callback=function(){})=>{
        const {props,action} = this.comp
        const {MultiInit,dispatch} = props
        MultiInit.getMultiLang({
            moduleId: 'gx6008',
            domainName: 'hrtrn',
            callback: (json,status,init) =>{
                dispatch({
                    type: 'main/update',
                    payload: {
                        json : json
                    } 
                })
                  //操作模版
                  action.pubAction.initMeta(props.meta.getMeta()) 
            }        
        })
    }

    

    initButton =()=>{
        const{props} = this.comp
        props.button.setButtonVisible({
            'delete': false,
            'add': false
        })
        props.button.setButtonDisabled({
            'delete': true,
        })
    }

    didMount =()=>{
        const{props} = this.comp
        if (window.location.href.match('localhost:3006'))   window.location.hash = '#/ifr?page=201981519'
            // window.location.hash = '#?&c=60091050&p=60091050nccloud'
        this.appConfig = getAppPageConfig()
        let height = document.documentElement.clientHeight;
        props.dispatch({
            type: 'main/update',
            payload: {
                pageHeight :  height - 215
            }
        })
        this.getTemplate()
        this.initButton()
        window.hh = this.comp
    }
}